package com.sc.auction.auction.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.auction.auction.pojo.Atuctionbargain;
import com.sc.auction.auction.pojo.Auctiondetails;
import com.sc.auction.auction.service.AuctionService;
import com.sc.auction.auction.service.AuctiondetailsService;
import com.sc.auction.common.util.R;
import com.sc.auction.common.util.Time;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pgc
 * @since 2020-09-01
 */
@RestController
@RequestMapping("/auction/auctiondetails")
public class AuctiondetailsController extends BaseController{
    @Autowired
    AuctiondetailsService auctiondetailsService;
    @ApiOperation("通过id查询")
    @GetMapping(value = "/getById")
    public R getById(@ApiParam(value = "id")@RequestParam Integer id){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("auctionId",id);
        Auctiondetails auctiondetails=auctiondetailsService.getOne(queryWrapper);
        return R.ok().data(" atuctionbargain",auctiondetails);
    }

    @ApiOperation("查询所有")
    @GetMapping(value = "/getAlldetails")
    public R getAlldetails(){
        return R.ok().data("details",auctiondetailsService.list());
    }

    @ApiOperation("增加明细")
    @PostMapping(value = "/putdetail")
    public R putdetail(@ApiParam(value = "明细")Auctiondetails auctiondetails){
        auctiondetails.setCreationDate(Time.getDate());
        boolean a=auctiondetailsService.save(auctiondetails);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("删除明细单")
    @DeleteMapping(value = "/deletedetails")
    public R deletedetails(@ApiParam(value = "拍品id")@RequestParam Integer id){
        boolean a=auctiondetailsService.removeById(id);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("修改明细单")
    @PutMapping(value = "/putdetails")
    public R putdetails(@ApiParam(value = "明细")Auctiondetails auctiondetails){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("auctionId",auctiondetails.getAuctionId());
        boolean a=auctiondetailsService.update(auctiondetails,queryWrapper);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }
}

